const fs = require("fs");
const path = require("path");
let str = `# Summary\n `;
const checkLimitDir = (dirs, ele) => {
  // console.log(`checkLimitDir ${dirs} -- ${ele}`)
  // return true: 需要限制
  // return false: 不需要限制
  let flag = false;
  if (!dirs.length) return flag;
  dirs.forEach((item) => {
    if (item === ele) flag = true;
  });
  return flag;
};
const readDir = ({ input, limitDirs }) => {
  const dirInfo = fs.readdirSync(input);
  dirInfo.forEach((item) => {
    const location = path.join(input, item);
    const info = fs.statSync(location);
    if (info.isDirectory()) {
      if (!checkLimitDir(limitDirs, location)) {
        // console.log(`dir item: ${item} `);
        // console.log(`dir: ${location} `);
        readDir({ input: location, limitDirs });
      }
    } else {
      if (!checkLimitDir(limitDirs, location)) {
        if (item.substr(-3, 3) === ".md")
          // list.push(fs.readFileSync(location) + "");
          str += `* [${item.substr(0, item.length - 3)}](${location})\n`;
        // console.log(`file: ${location} `);
      }
    }
  });
};
module.exports = {
  getDirList(val) {
    readDir(val);
    return str;
  },
};
